import express from 'express';
import { Controller } from './controller';
import multer from 'multer';
// 定义diskStorage对象
const storage = multer.diskStorage({
    // 对存储路径进行配置
    destination: function(_req, _file, callback) {
        callback(null, 'upload/images/');
    },
    // 对文件名进行配置
    filename: function(_req, file, callback) {
        callback(null, `${Date.now()}_${file.originalname.split('.').pop()}`);
    }
});

// 定义multer对象
const upload = multer({
    storage
});
export default express
    .Router()
    .post('/image/upload', upload.single('file'), Controller.upload);